Skip to content

Put inline math on the text baseline on iOS - #314

Merged
max-miller1204 merged 3 commits into
mainfrom
fix/ios-answered-card-baseline
Nov 21, 2026
Merged

max-miller1204 merged 3 commits into
mainfrom
fix/ios-answered-card-baseline

Conversation

@max-miller1204

@max-miller1204 max-miller1204 commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

What changed and why

Owner bug 1: on iPhone, the math in the answered quiz card ("4", "8", the signed pair) sits below the text around it. #313 is the same bug seen from the period's side: the math sits low, so a period after it looks raised. Fixes #313.

Measured. In the iPhone check's shots from before any lift (run 44871251269, 3x), a digit's ink bottom sits 12 to 13 px (4.0 to 4.3 pt) below the bottom of the letters on 16 pt text with 24 pt lines. That covers the answered card, the explanation, the message prose and the table rows. On a 14 pt choice row ("Train: 4; test: 8", 21 pt line) it sits 9 px (3.0 pt) low. After the fix (run 44884978315) the same spots read 0 to -1 px; the table is in the PR comments.

Cause. React Native 0.88.1's iOS text sets an inline view's frame at glyphRect.origin.y + glyphRect.size.height - attachmentSize.height + font.descender (RCTTextLayoutManager.mm:631). That puts the view's bottom at the line's bottom plus the descender of its character's font. Two things make that the wrong place:

  • The attachment character is built with no attributes besides the attachment (RCTNSAttributedStringFragmentFromFragment, RCTAttributedTextUtils.mm:409-419), so the font it reads is TextKit's default, Helvetica 12. Its descender is 2.76 pt at any text size, where the text's is 0.4 em (6.4 pt at 16 pt).
  • The text's baseline is its line's largest descent up from the bottom, and React Native raises it by (lineHeight - tallest font line height) / 2 over the whole Text (RCTApplyBaselineOffsetForRange, RCTAttributedTextUtils.mm:345-384). The frame ignores that.

So the view sits line descent + baselineOffset - 2.76 below the baseline: 6.4 + 0.61 - 2.76 = 4.25 pt at 16/24 (measured 4.17 on average). Upstream fixed this by placing the view from the baseline TextKit reports for its line (react/react-native#59921, 5c062e6dd3, in no release yet). Its message names both faults.

Fix, JS only, in apps/mobile/src/MathLabel.tsx:

  • inlineLift computes that distance on iOS, in points at the font scale (Helvetica's descender doesn't grow with Dynamic Type), and the inline MathPicture is moved up by it with a translateY.
  • The descent is from the fonts on the hard line the math is on: Source Sans 3, and JetBrains Mono for inline code, with a break belonging to the line it ends. The offset uses every font in the Text.
  • A line with no text gets no lift. Its only font is the attachment's Helvetica, so its math already sits on its baseline. That covers a math-only label and a math-only line after a newline.
  • The lift never takes a picture above its line's top. A picture taller than the room above the baseline sits lower instead, and no line grows: line heights are exactly what they were before this PR.
  • A soft-wrapped line holding only math is lifted as if it held its hard line's text, and still stays inside its line (documented on inlineLift).
  • NativeMarkdown.tsx gives each equation its line's fonts, which fixes the period after message math.

Tests, apps/mobile/tests/math-baseline.test.ts:

  • A tripwire fails if React Native stops placing inline views this way (for example when #59921 ships), because the lift would then raise every picture above the text.
  • The rendered lift must match the measured gaps on the answered card and the choice row (real line heights), within 0.5 pt.
  • Lifted on iOS for the answered card and message math; never on Android; never for math alone, alone after a newline, or in a math-only label.
  • The line's own fonts set the lift (code-only line: 2.048 pt).
  • iOS line heights equal Android's, and tall or deep \rule math stays inside its line.

Verified

  • Mobile unit tests, one file at a time under a 300s cap: all 14 files pass (math-baseline.test.ts: 7 tests). The round 2 tests fail on 6a27bf4, and mutations (no transform, no cap, lifting math-only lines) are each caught.
  • npm run typecheck and npm run lint in apps/mobile: pass.
  • iOS fingerprint (npx expo-updates runtimeversion:resolve --platform ios) is b294c68b58b762e9cac472a7ee00c0a6127b4216, the same as main, so this ships as an OTA update.
  • Android: the lift is 0 and no transform is set, and its line heights are computed as before, so Android renders exactly what it did. The unit test covers this. I took no Android emulator shot, because this desktop can't run one beside everything else without the ThinkPad. The prove check covers Android.
  • iPhone CI job: the answered-quiz shots and pairs in iphone-screenshots, measured at the same spots, plus the fixture's tall-rule paragraphs.

Source

  • node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextLayoutManager.mm:621-632 (attachment frames)
  • Same directory, RCTAttributedTextUtils.mm:345-402 (RCTApplyBaselineOffsetForRange, applied over the whole Text) and :405-419 (attachment fragments have no font)
  • Position iOS inline views from their line's actual baseline (#59921) react/react-native#59921 (5c062e6dd3), the upstream fix
  • Shots: run 44871251269 (before), 44884978315 (after)
  • Bundled fonts' hhea metrics: Source Sans 3 1024/-400 (every weight and slant), JetBrains Mono 1020/-300

With a lineHeight, React Native's iOS text raises glyphs by half the line's
extra height but places inline views from the line's bottom and the font's
descender without that raise, so inline math sat that far below the text.
That is the answered quiz card's math sitting low and, in messages, the
period after inline math looking raised (#313). Each inline picture is now
lifted by the same amount on iOS; Android places views on the baseline and
gets no lift.

Verified: checks
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Preview ready for 647eeb9bf77e (0.6.1-preview.20261121.221). On your server:

lh preview 314

It runs beside your server on port 3775 with fresh, empty data, and Ctrl+C stops it and deletes it. Release files. Each push builds a new one.

…aseline

Measured on the iPhone check, inline math sat about 4.2 pt low on 16/24 lines
and 3 pt low on 14/20 lines, far more than the baseline offset alone. React
Native 0.88's iOS text puts an inline view's bottom at its line's bottom plus
its character's font descender, and that character has no font, so TextKit's
default Helvetica 12 is used. The lift now undoes exactly that: the text's
baseline (its descent plus React Native's baseline offset, over every font in
the line, at the font scale) less Helvetica 12's 2.76 pt descender. A Text with
only math gets no lift, and on iOS a line grows to hold tall or deep math once
lifted. A test fails when React Native changes this placement.

Verified: checks
@max-miller1204

Copy link
Copy Markdown
Owner Author

Round 1 review, addressed in 6a27bf4.

Important

  1. The lift was far too small: fixed, with the real cause. I measured the pre-fix shots (run 44871251269, 3x). On 16/24 lines a digit's ink sits 12 to 13 px below the letters' bottoms: the answered card, the explanation, message prose and table rows. On a 14/20 choice row it sits 9 px low. Every one of those lines has lineHeight 24 (or 20); lineHeightFor never enlarged them. So the baseline offset can't be most of it. The lead was right: the attachment character has no font (RCTAttributedTextUtils.mm:409-419), so the frame's font.descender (RCTTextLayoutManager.mm:631) is TextKit's default Helvetica 12, 2.76 pt, not 0. The view's bottom is the line bottom plus that, and the text baseline is its descent plus the NSBaselineOffset. Predicted 4.25 pt at 16/24 (measured 4.17) and 2.87 pt at 14/20 (measured 3.0). The second size is an independent check: my first model predicted 0.03 pt there. Upstream Position iOS inline views from their line's actual baseline (#59921) react/react-native#59921 (5c062e6dd3, 2026-11-20, unreleased) fixes the same frame by asking TextKit for the line's baseline. The lift is now textDescent + baselineOffset - 2.76, in points at the font scale (Helvetica doesn't scale). No fixture experiment was needed: two font sizes were already in the shots. The post-fix iPhone run is the proof: the same spots should measure about 0.
  2. Math-only labels: fixed. A Text with no text gets no lift. Helvetica is its only font, so the view is already on its baseline, and lineHeight doesn't apply (no paragraph style). Tested with $\rule{1em}{4em}$ alone and the signed pair alone.
  3. Tall inline math standing out: fixed. lineHeightFor on iOS now also takes the least line height that holds each lifted picture inside its line: 2(top + descent) - tallest font and 2(depth - descent) + tallest font, the same bound as Claude's. Normal lines are unchanged. Tested with \rule{1em}{4em} and \rule[-2em]{1em}{1em} after a first line; it fails with the old line height ("top 116.9 inside 89").

Nits

  • Fonts: the lift and the line height use every font in the line, from the real hhea metrics (Source Sans 3 1024/-400 in every weight and slant, JetBrains Mono 1020/-300 for inline code at 14). NativeMarkdown passes the line's runs, including nested code.
  • The formula test is gone. It's replaced by a tripwire on React Native's placement code, so the test fails when #59921 ships and the lift must go, plus checks against the measured screenshot gaps (within 1 px).
  • Unmount is in finally.
  • The history comment is gone; the comments state only the mechanism, and the history is in the PR body.

Also seen, separate from the baseline: in the pre-fix shots, a math-only signed pair (−0.10, +0.20) has the tops of its digits cut flat while the parentheses above them are whole (quiz-waiting-light-13.png, choice rows 2 and 4, and the answered card's lone pair in quiz-answered-light-5.png). It isn't a box clip, so it isn't this bug. I'll check the post-fix shots to see whether it's still there.

@max-miller1204

Copy link
Copy Markdown
Owner Author

Measured, before and after (iPhone check, 3x pictures). Before is run 44871251269 (main, no lift); after is run 44884978315 (6a27bf4, green). Each gap is the bottom of the math's ink (a digit, or w for "w + Δw") minus the bottom of the letters on the same line, in px; a positive gap means the math sits low. Text without descenders was used, and the x range excludes punctuation.

Spot Font / line Before After
Answered card "Train: 4; test: 8" (-1/-2) 16/24 12 px (722 vs 710) -1 px (4: 2060 vs 2061), 0 px (8)
Answered card "Train: 4; test: 8, (+0.20, −0.10)" (-5) 16/24 12 px (1731 vs 1719) -1 px (1718 vs 1719)
Explanation "One third of 12 is 4" 16/24 12 px (722 vs 710) -1 px (2227 vs 2228)
Explanation "Each change is −0.1" 16/24 12 px (937 vs 925) -1 px light, 0 px dark
Question "is 0.1." 16/24 13 px (629 vs 616) 0 px (616 vs 616)
Message "since 4 < 8" 16/24 12 px (2118 vs 2106) -1 px light, 0 px dark
Message "so it equals 0.2. The" (#313) 16/24 13 px (1272 vs 1259; the period at 1259) 0 px (763 vs 763; the period at 763)
Message "ends at w + Δw." (#313) 16/24 12 px (1343 vs 1331; the period at 1331) -1 px (834 vs 835; the period at 835)
Table row "Then … 0.2." 16/24 13 px (409 vs 396) 0 px (396 vs 396)
Choice row "Train: 4; test: 8" (quiz-waiting-light-13) 14/20 9 px (1429 vs 1420) -1 px (1419 vs 1420)

-1 px is one third of a point, which is anti-aliasing at the ink threshold. Dark matches light (the -5 spots measured in both).

Also checked in the after run:

  • Line heights. The text's ink rows are pixel-identical before and after on every measured line, and the choice rows' borders haven't moved, so lines stayed at 24 and 20.
  • Math-only choices and the answered card's lone pair. Their ink is at the same rows as before (1518-1557 and 1792-1831 on quiz-waiting-light-13; 735-780 on quiz-answered-*-5, light and dark). They were not moved.
  • Overlap. Nothing overlaps or clips in the answered shots or the width-ladder table. The fixture has no math taller than parentheses; the tall and deep \rule cases are covered by the unit test.

Cut tops, unchanged and not caused by this PR. In a Text that holds only math (the choice rows (−0.10, +0.20) and (+0.20, −0.10), and the answered card's lone (+0.20, −0.10)), the picture is cut at one horizontal row. Every glyph starts on that row: the parentheses, the plus sign and the digits (1518 px on the choice rows, 735 on the card). The same pair drawn after text is whole at 16 pt: parenthesis 57 px tall, digits 39 px. Alone it shows a parenthesis of 45 px and digits of 36 px, so about 3 px is gone above the digits and a few px off the parenthesis's bottom. The window is about the size of the inline box (the math above the baseline, 14.5 pt). The pixels are identical before and after this PR, and in light and dark. Not filed; left for the owner to decide.

…lines

TextKit sets each line's baseline from that line's fonts, so the lift now uses
the descent of the hard line the math is on, and none for a hard line holding
only math, as for a math-only label. React Native's baseline offset is worked
out over the whole Text, so that part still uses every font. Instead of
growing every line of a paragraph for tall math on iOS, the lift is capped so a
picture never rises above its line's top; line heights are back to what they
were. Inline code's size is one constant, the choice-row check uses the real
21 pt line, and the iPhone fixture gains a tall rule alone after a newline and
a plain line above a line with a tall rule.

Verified: checks
@max-miller1204

Copy link
Copy Markdown
Owner Author

Round 2 review, addressed in 647eeb9. Each fix has a test that fails on 6a27bf4.

Important (Codex)

  1. The lift used fonts from the whole Text: fixed per hard line. I checked React Native's source:

    • TextKit sets each line's baseline from that line's fonts.
    • RCTApplyBaselineOffset runs once over the whole range (RCTApplyBaselineOffsetForRange(attributedText, NSMakeRange(0, attributedText.length)), with enableIOSTextBaselineOffsetPerLine off), so the offset is the same for every line.
    • An inline view's frame ignores both, and is always the line bottom plus Helvetica 12's 2.76 pt.

    So the lift now uses the descent of the hard line the math is on, where a break belongs to the line it ends, and the whole Text's tallest font for the offset. A hard line with only math gets no lift: its only font is the attachment's Helvetica, so the view is already on its baseline, as with math-only labels. NativeMarkdown walks the tokens, including nested spans, to give each equation its line's fonts; MathLabel splits its text at newlines.

    • Tests: Earlier text, newline, $\rule{1em}{4em}$ is not lifted (65.248 pt on 6a27bf4). Some words first, newline, `k`$x$ is lifted by 4.2 + 0.608 - 2.76 = 2.048 pt (4.248 on 6a27bf4).
    • Accepted edge case, documented in inlineLift's comment: a soft-wrapped line holding only math (or only code and math) is lifted as if it held its hard line's text. With the cap below it stays inside its line.
  2. Tall math grew every line: fixed by dropping the growth. lineHeightFor is back to what it was before this PR on both platforms. Instead, the lift is capped so a picture never rises above its line's top: room = (L - box) * fontScale - 2.76. That works on any line, because the view's bottom is always 2.76 pt above the line's bottom. A picture taller than the line leaves above the baseline sits lower instead. The line heights this PR leaves already hold deep math once lifted: on iOS the room under the baseline is (L - ascent + descent) / 2, which is at least the depth.

    • Tests: line heights on iOS equal Android's for Earlier text / Rule: $\rule{1em}{4em}$. (146 vs 85 on 6a27bf4), a deep \rule[-2em] and the ordinary message line. Each lifted picture stays between its line's top and bottom; that check fails with the cap removed. Normal lines stay at exactly 24, and the choice row at 21.

Nits (Claude)

  • Choice row line height: it's 21 pt (paragraphLine makes 14/20 into 21, as before this PR). The test now reads the line height from a rendered ChoiceRow and takes the lift from the rendered picture, so both measured cases use the real line: 3.37 pt predicted against 3.0 measured. The tolerance is now 0.5 pt, with the reasons in the test: one ink pixel is 1/3 pt, and React Native rounds the view's origin to the pixel grid. The after-fix spots read 0 to -1 px, which fits a 0.17 to 0.37 pt overshoot.
  • Inline code size: CODE_SIZE is one constant, used by the code span and by the line's fonts.

Proof: the iPhone fixture's final reply gains A plain line comes first + newline + $\rule{1em}{4em}$, and Another plain line + newline + Then a rule: $\rule{1em}{4em}$ on this line. (about two screens more; the last job took 37 min of its 75). The iOS fingerprint is still b294c68b. Run: https://github.com/max-miller1204/learnharness-nightly/actions/runs/44889291506

@max-miller1204

Copy link
Copy Markdown
Owner Author

Measured on 647eeb9 (run 44889291506, green; 3x pictures). Gap = bottom of the math's ink minus bottom of the letters on the same line, in px (positive = math low). Pages shifted with the longer fixture, so each spot was found by matching pixel rows with round 1 (page 2 matches at +496 px with zero difference).

Spot Font / line Before (44871251269) Round 1 (6a27bf4) Round 2 (647eeb9)
Answered card "Train: 4; test: 8" 16/24 12 -1 / 0 -1 / 0
Answered card "Train: 4; test: 8, (…)" 16/24 12 -1 -1
Explanation "One third of 12 is 4" 16/24 12 -1 -1
Explanation "Each change is −0.1" 16/24 12 -1 -1
Question "is 0.1." 16/24 13 0 0
Message "since 4 < 8" 16/24 12 -1 -1
#313 "so it equals 0.2. The" (and its period) 16/24 13 0 0
#313 "ends at w + Δw." (and its period) 16/24 12 -1 -1
Table row "Then … 0.2." 16/24 13 0 0
Choice row "Train: 4; test: 8" 14/21 9 -1 -1 (shot pixel-identical to round 1)

Line heights. Ordinary prose lines advance 72 px (24 pt): the "The first pair fits" paragraph's three lines. The text rows of every measured line are where they were in round 1. The choice rows are pixel-identical to round 1, so they're still 21 pt. The math-only choice pairs are unchanged (ink rows 1518-1557 and 1792-1831).

The new tall-rule paragraphs (quiz-answered-*-5):

  • "Another plain line" / "Then a rule: [rule] on this line." The baselines are 1904 and 2159, so both lines are 85 pt (255 px). The rule spans 2017 to 2248. Its top lands exactly on its line's top: the line's bottom is 2159 + 37.5 pt = 2271.6, so its top is 2016.6. That is the cap, and nothing reaches the plain line above. The rule's bottom sits 89 px (29.7 pt) below the baseline: on iOS, React Native centres the text in an 85 pt line, so a 77 pt rule can't stand on the baseline without the line growing. On main it sat 104 px (34.7 pt) low.
  • "A plain line comes first" / the rule alone. "A" sits on 1286 and the rule spans 1484 to 1715, so it starts 85 px below the first line's 85 pt box and ends 8 px (2.76 pt) above its Text's bottom. There's no lift and no overlap. The math-only line has no paragraph style of its own, so it lays out at its natural height, including React Native's baseline offset.
  • Plain lines are 85 pt, not 24. That's paragraphLine's height for a paragraph holding the 4 em rule, the same on main and on Android, because React Native's lineHeight applies to the whole Text. This PR no longer grows it (146 pt on 6a27bf4). Keeping a plain line at 24 would mean splitting a paragraph into a Text per hard line, which this PR doesn't do.

Separate, not filed. The \rule renders pure black (0,0,0) rather than the text colour, so in dark mode it nearly vanishes into the background. It's drawn as a rectangle, and this PR doesn't touch how math pictures are coloured (svg-flatten.ts, the currentColor rewrite in choice-math.ts). Left for the owner to decide.

@max-miller1204

Copy link
Copy Markdown
Owner Author

prove-learnharness: PROVED for 647eeb9

Couldn't prove physical TestFlight or VoiceOver speech from the CI artifacts. All checks requested for this diff passed.

Check Observation
iPhone baseline, light and dark Measured the answered card, explanation, both #313 sentences, table, width ladder and choice row. Math was 9 to 13 screenshot pixels low before. Head was within 2 px of the letters at 3x and matched the web's alignment.
iPhone spacing and math-only lines Ordinary text stayed on the same pixel rows. The two math-only choices and the math-only answered label kept their ink positions.
iPhone tall rules Both rules cleared the previous line by 188 and 103 px in each theme. The web pair also had clear space above both rules.
Android Installed head and origin/main release APKs and opened the same fixture. The answered cards, inline-math message, table and tall rules were pixel-identical within the app frame. The waiting quiz differed only where the transient scrollbar appeared.
Mechanical checks 154 mobile tests passed one file at a time, 5 skill link checks passed, and mobile typecheck passed. Both fingerprints matched main.
Known issues #315 math-only top clipping and #317 black rule color were visible and already filed.

Receipt .prove-it/runs/20261121T125954Z-pr-314-device-27d7c0/receipt.md.

Proof receipt

Receipt for PR #314, iPhone inline math baseline

Verdict: PROVED
Checker: fresh sub-agent, independent of the implementation
Scope: merge base 17c7202 to head 647eeb9. Android and fingerprint answer key: origin/main at 046ca3e.
Changed files: apps/mobile/src/MathLabel.tsx, apps/mobile/src/NativeMarkdown.tsx, apps/mobile/tests/math-baseline.test.ts, tests/fixtures/mobile-quiz/scenario.json.
Surfaces driven: iPhone 17 CI screenshots at 3x, paired web screenshots, locally installed Android 16 release APKs, and a supplemental web capture of the expanded explanation.
Scripted run: .prove-it/runs/20261121T125601Z-pr-314-3d2a1e. Device run: .prove-it/runs/20261121T125954Z-pr-314-device-27d7c0.

What the change touches

  • Existing answered quiz cards, explanations, questions, choice rows, inline-math messages and table cells. Compare the corrected baseline with the web and the two bug captures. Compare spacing and math-only rendering with main.
  • New tall rules in the synthetic scenario exercise an existing message renderer. Compare overlap with the web and apply the user's cap and no-line-growth requirements.
  • Existing Android rendering and OTA compatibility. Compare both with origin/main.
  • The same disposable server, fake model and head fixture served both Android APKs. The Android test used one Pixel 6a AVD, serial emulator-5554, Android 16 API 36, x86_64. The generated native project used an isolated package ID, a throwaway CA for emulator loopback, and disabled fetching OTA bundles so that each installed APK ran its own embedded JS. The Expo fingerprints were checked before those test-only changes.

iPhone observations

These are ink-bottom gaps in screenshot pixels. Positive means the math is lower than the neighboring letters. Light and dark are listed separately. Phone captures are 3x. CI web pairs are 1x and the supplemental web explanation is 3x. The measurement uses columns with no descending letters and masks at luminance 145 for light or 125 for dark. The web explanation uses a lighter threshold for its muted text. Anti-aliasing shifts some ink edges by one pixel.

Spot Before light / dark Head light / dark Web light / dark
Answered card, 4 and 8 +11, +12 / +11, +12 −2, −1 / −2, −1 0, 0 / 0, 0
Explanation, 12 and 4 +11, +11 / +11, +11 −2, −2 / −2, −2 0, 0 / −1, −1
Message, 0.2 and its period +13, 0 / +12, −1 0, 0 / −1, −1 0, 0 / 0, 0
Message, first w and the period after w + Δw +12, 0 / +11, −1 −1, 0 / −2, −1 0, 0 / 0, 0
Train table cell, 4 and 12 +12, +12 / +11, +11 −1, −1 / −2, −2 −1, −1 / −1, −1
Width ladder, final 2 +12 / +12 −1 / −1 0 / 0
Waiting choice, 4 and 8 +9, +10 / +9, +10 −1, 0 / −1, 0 0, 0 / 0, 0
  • PASS. The signed pair on the answered choice line also sits on the surrounding text baseline. The two digit samples moved from +12 and +11 px before to −1 and −2 px in light and −1 and −1 px in dark. Its parentheses extend below the digit baseline, as on the web. The independent measurements agree with the PR table within the sampled ink edges and screenshot rounding.
  • PASS. Additional iPhone samples from the PR table agree: the question’s 0.1 moved from +12 to −1 px, the second explanation’s −0.1 from +12 to −1 px, and the first digit after “since” from +12 px to 0 or −1 px in light or dark.
  • PASS. Ordinary prose text occupied the same pixel rows before and after in each theme. The message's period rows remained 72 px apart. Repeated width-ladder text rows remained 109 px apart, including paragraph spacing. The web had the same visual line order and punctuation placement with its own font and spacing.
  • PASS. The two math-only waiting choices had the same ink rows as before, 1518–1557 and 1792–1831. The signed pair in the answered card's math-only label also kept its rows, 694–739 in waiting shot 10. The web equivalents retain their full glyph shapes. The known iPhone clipping is iPhone: a line of only inline math is clipped at the top #315.
  • PASS. In both themes the tops of the two tall rules cleared the previous line's ink by 188 and 103 px, respectively. The corresponding web gaps were 5 and 6 px in the 1x screenshots. The mixed second rule sits below the text baseline on iPhone with the cap, while the web rule bottom aligns with the text. The rule remains inside its allocated line and clear of the line above, as specified. The known black rule color is Phone: math \rule draws black instead of the text colour (invisible in dark mode) #317.
  • PASS. The scratch bug run shows the first answered card digits 11–12 px low and examples of a separated period in the width ladder. Its two named prose endings already have zero ink gap with its earlier rendering. The before run with the main mobile source gives the 11–13 px prose gaps measured above.
  • Sources: CI head run 44889291506, before run 44871251269, scratch run 44871247251. The before run reports workflow SHA 3b53cd6. Git comparison showed the same apps/mobile and fixture files as origin/main. The scratch run reports b65522c, a capture branch descended from 133ebf2. See iphone-evidence/, iphone-measurements.txt and web-supplement/. The stock web pair keeps Why closed, so the explanation was opened on the same synthetic fixture for the extra measurement.

Android and mechanical checks

Step Observation
Android emulator health PASS. One AVD booted. Window dumps succeeded, with no System UI stall or ANR at boot or after the drive.
Android waiting quiz PASS. Same question, option rows, controls, and spacing. All 12,041 differing app pixels were in columns 1036–1046, where the transient dock scrollbar appeared.
Android answered cards and table PASS. Zero differing app pixels in the aligned top and message screenshots.
Android inline math and tall rules PASS. Zero differing app pixels in the inline-math and answered-rule captures, including both tall rules. Submitted the waiting quiz once in the head app and reopened the same saved session under main.
Mobile unit suites PASS. 154 tests across 14 files run one file at a time. The maintained skill also passed 154 unit tests and 5 link-prompt checks.
Mobile typecheck PASS. npm run typecheck under Node 22.23.5.
OTA fingerprint PASS. Head and main both resolve to iOS b294c68b58b762e9cac472a7ee00c0a6127b4216 and Android f5bb079b3763b614ffd3e8076dcba382425718a3. The Expo native module check passed.

Android region comparisons exclude system status chrome. See android/diff.txt, android/build-summary.txt and the PNGs. The selected rows and resulting synthetic reply are recorded in android/head-selection.txt and android/fixture-result.json.

Probes

  • PASS. The installed RN 0.88.1 source creates an attachment character without a font attribute and positions it with the glyph rectangle and character font descender. The frame calculation omits the baseline offset applied over the Text. The 7 baseline tests independently passed the native source tripwire, per-hard-line font runs, math-only hard line, iOS-only lift, unchanged line heights and tall/deep cap cases.
  • PASS. Two Android APKs installed successfully and gave the same result on the same saved transcript with its math fixture.

Retries and fixes

  • Android discovery initially reported “The device hub did not answer within 40 seconds,” and ADB timed out. The repeated health check found both AVDs off and ADB responding. Only the requested AVD was opened.
  • The first extra web capture had a wrong fixture path, and a subsequent capture was under the waiting dock. Used the fixture's actual chat ID and centered the expanded explanation above the dock.
  • One Android selector for the fourth choice was rejected. A fresh accessibility snapshot gave the checkbox ref and the tap succeeded.
  • T3 shutdown reported “Could not communicate with device support. Try refreshing devices.” The follow-up device listing and ADB/process checks are recorded in the cleanup evidence.

Not covered

Physical TestFlight, VoiceOver speech and store-track acceptance are outside this diff's CI and emulator proof. There was no OTA publication. Known and filed observations: #315 math-only top clipping and #317 rule color.

Left behind

Evidence in the two proof folders and the isolated temporary checkout. The test APK was uninstalled, the default keyboard was restored to Gboard and read back, and the disposable server, TLS proxy and fake model were stopped.

@max-miller1204
max-miller1204 merged commit 9aa828e into main Nov 21, 2026
19 checks passed
@max-miller1204
max-miller1204 deleted the fix/ios-answered-card-baseline branch November 21, 2026 13:14
max-miller1204 added a commit that referenced this pull request Nov 21, 2026
…#318)

Fixes two phone math bugs.

**#315, iPhone: a line of only inline math was clipped at the top and bottom.** React Native's Text clips to its frame. A Text with no text gets no line height, and Fabric places the picture 2.76 pt too high (a fontless attachment's Helvetica 12 descender).
- **The fix:** math in a text-less Text moves down 2.76 pt plus a 0.5 pt pixel-rounding margin (3.26 pt in all).
- **Padding:** the Text gets bottom padding for the math's depth plus 1 pt, added to any existing padding such as a table cell's.
- **Growth:** math-only rows and lines grow by about 5 to 6 pt, and nothing else changes size.

**#317: `\rule` drew black.**
- **The fix:** a rule now takes the colour of its nearest coloured ancestor, as glyphs do, else the text colour. Only MathJax's literal `black` default is rewritten.
- **Edge cases:** zero-size struts are ignored, and `\colorbox`, `\boxed`, `\fbox`, fraction bars, `\sqrt` and `\overline` are unchanged.

**The final check:**
- **iPhone:** whole pairs at 3x, and the rule in the text colour in light and dark.
- **#314's baseline:** unchanged.
- **Android:** pixel-identical to main except the rule colour.
- **Mechanical:** 158 tests, and unchanged fingerprints (OTA).

It reported BROKEN only on three points:
- the lift is 3.26 pt and a lone-pair card grows by 6 pt, which is the round 2 rounding margin and was expected, though the check's brief still said 2.76 pt and 4 to 5 pt;
- an author's explicit `mathbackground="black"` on a raw `mspace` is recoloured, a limitation accepted in review because it can't be told from MathJax's default.

Following the owner's standing instruction to act without asking, these are accepted and the PR is merged.

Closes #315. Closes #317.

Verified: checks, /code-review, codex, /prove-learnharness (all behaviour confirmed; BROKEN only on an outdated brief and an accepted limitation)
max-miller1204 added a commit that referenced this pull request Nov 22, 2026
On the phone, stretched math drew in loose pieces: `\underbrace`, `\overbrace`, `\xrightarrow`, `\overrightarrow`, `\overline`, tall `\left\{`. MathJax places the stretched middles as nested `<svg>` elements with `x`/`y`, and react-native-svg 15 drops a nested `<svg>`'s `x`/`y` on both platforms (`RNSVGGroup.mm`, `SvgView.drawChildren`). The pieces landed at their group's origin: the double bars under the owner's floor bracket and the ":" beside the "1".

**The fix:**
- `drawTex` (`apps/mobile/src/choice-math.ts`) wraps every nested `<svg>`, at any depth, in its own `<g>`, carrying its offset as `translate(X,Y)`. That also contains any clip or viewBox state the library leaves behind.
- Offsets are parsed with the flattener's shared `SVG_NUMBER` grammar, and anything else falls back to the source text.
- The #279 safety allowlist still checks the final markup.

**Checks:**
- **Pixel tests:** a resvg pixel test with `@resvg/resvg-js` as a dev dependency covers 29 expressions, in both themes, inline and display, and matches MathJax's intended rendering. Unaffected math is byte-identical.
- **The iPhone fixture:** it now includes the owner's equation and an `\xrightarrow`.
- **The final check:** it showed both underbraces and the arrow whole, matching the web in light and dark. #314's baseline was pixel-identical to main.
- **Tests and shipping:** 165 mobile tests passed, and the fingerprints are unchanged (OTA).

Android wasn't driven, because its host was restarting.

Closes #338.

Verified: checks, /code-review, codex, /prove-learnharness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iPhone: a period after inline math sits raised like a centered dot

1 participant